/**
 * GradientTextView
 * @Chunning.Xu
 * 2011 Nov 23, 2011 8:18:06 PM
 **/
package com.lux.product.views
{
	import flash.display.DisplayObject;
	import flash.display.GradientType;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.Font;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFieldType;
	import flash.text.TextFormat;
	
	public class GradientTextView extends Sprite
	{
		//START.
		
		private var _text:String;
		
		private var tf:TextField;
		private var fade:Shape;
		
		private const FONT_NAME:String = "SimSun";
		private const FONT_SIZE:Number = 19;
		
		public function GradientTextView()
		{
			tf = new TextField;
			tf.type = TextFieldType.DYNAMIC;
			tf.multiline = false;
			tf.selectable = false;
			tf.autoSize = TextFieldAutoSize.LEFT;
			tf.embedFonts = true;
			this.addChild(tf);

			fade = new Shape;
			addChildAt(fade,0);
			
			fade.mask = tf;
		}
		
		public function set text(_text:String):void
		{
			this._text = _text;
			tf.htmlText = "<b>" + _text + "</b>";
			
			var format:TextFormat = tf.getTextFormat();
			format.font = FONT_NAME;
			format.size = FONT_SIZE;
			tf.setTextFormat(format);
			
			fade.graphics.clear();
			fade.graphics.beginGradientFill(GradientType.LINEAR,[0xe9c376,0x9a732c],[1.0,1.0],[0,255]);
			fade.graphics.drawRect(0,0,tf.width,tf.height);
			fade.graphics.endFill();
		}
		
		public function get text():String
		{
			return _text;
		}
		
		//END
	}
}